<?php
/**
*   Responsible for build logs
*   @author Renan Henrique Abreu <renanhabreu@gmail.com>
*   @date 20-02-2009
*   @version 3.0
*   @package Nucleo
*   @subpackage Nucleo.Exception
*   @copyright 2009 Renan Abreu
*/
class Nucleo_Exception_Sifra extends Exception implements Nucleo_Exception_Interface{
	protected $exceptionName = 'Sifra';

        public function __construct($message, $translation = false) {
            if($translation)
                $message = Nucleo_Language_Translate::sifraMsg($message);
            parent::__construct($message);
        }
        
	public function getError(){
			
		$info = $this->getTrace();
		$error = $info[0];
		$error['ipUser'] = $_SERVER['REMOTE_ADDR'];
			
		$log = '
		========================================================================
		========================================================================
		Date  :::::: '.date('d/m/Y -- H:i:s').'
		Error :::::: '.$this->getMessage().'
		File  :::::: '.$error['file'].'
		Line  :::::: '.$error['line'].'
		Function ::: '.$error['function'].'
		/////////////////
		///// ABOUT USER
		////////////////		
		IP    :::::: '.$error['ipUser'].'
		HOST  :::::: '.gethostbyaddr($error['ipUser']);
		
		if(LOG_IN_FILE){
			$file = LOG_PATH.$error['ipUser'].'.out';	
			$fp = fopen($file,'a+');
			fwrite($fp,$log);
			fclose($fp);
			
			$fp = fopen(LOG_PATH.'logs_ip.out','a+');
			$ips = "
			".$error['ipUser']."  ".date('d/m/Y')."--".date('H:i:s');
			
			fwrite($fp,$ips);
			fclose($fp);
			
			$fp = fopen(LOG_PATH.$this->exceptionName.'.out','a+');
			fwrite($fp,$log);
			fclose($fp);
			
		}else{
			echo $log;
		}
	}
	
}

?>
